package com.sel.controle;

import java.util.List;

import com.sel.modelo.Laboratorio;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class Gestao_reserva_laboratorio extends Activity
{
	private ListView lista;
    protected Laboratorio laboratorio;
    public static Gestao_reserva_laboratorio gestao_reserva_laboratorio;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gestao_reserva_laboratorio);
        
        lista = (ListView) findViewById(R.id.lv_gestao_reserva_laboratorio);
        
        lista.setOnItemClickListener(new OnItemClickListener() 
        {
            @Override
            public void onItemClick(AdapterView<?> adapter, View view,int posicao, long id) 
            {
            	laboratorio = (Laboratorio) adapter.getItemAtPosition(posicao);
                reservaEquipamento();
            }
        });
    }
    
    protected void reservaEquipamento() 
    {
        Intent intent = new Intent(getApplicationContext(), Reserva_laboratorio.class);
        Bundle bundle = new Bundle();
        bundle.putInt("ID_LABORATORIO", laboratorio.getId());
        bundle.putInt("NUMERO_LABORATORIO", laboratorio.getNumero_Laboratorio());
        bundle.putInt("CAMPI_LABORATORIO", laboratorio.getCampi_laboratorio());
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    protected void onResume() 
    {
        super.onResume();
        carregaLaboratoriosCadastrados();
    }

    private void carregaLaboratoriosCadastrados() 
    {
        Laboratorio objLaboraotios = new Laboratorio();
        List<Laboratorio> laboratorios = objLaboraotios.listaLaboratoriosPorCampi(getApplicationContext(),Sessao.usuario.getIdcampi());
    	int layout = android.R.layout.simple_list_item_1;
    	ArrayAdapter<Laboratorio> adapter = new ArrayAdapter<Laboratorio>(this, layout, laboratorios);
    	lista.setAdapter(adapter);
    }

}
